Financial charts may create some confusion, never the less, making them works on the same principal as any other chart. There is, however, a difference in acquiring data.
Data Acquisition
First let's get data from a database which already has open, close, high, and low values using the DataEngine. In order to populate OCHL (open, close, high, low) element properties the DataEngine.GetFinancialSeries() method is used instead of GetSeris().
[C#]DataEngine de = new DataEngine(myConnectionString);
de.QueryString = "SELECT timeCol ,openCol, closeCol, highCol, lowCol, timeCol FROM stockPrice";
de.DataFields = "open=openCol,close=closeCol,high=highCol,low=lowCol,xValue=timeCol";
SeriesCollection stockSC = de.GetFinancialSeries();
stockSC[0].Type = SeriesTypeFinancial.CandleStick;
Chart.SeriesCollection.Add(stockSC);
[Visual Basic]Dim de As New DataEngine(myConnectionString)
de.QueryString = "SELECT timeCol ,openCol, closeCol, highCol, lowCol, timeCol FROM stockPrice"
de.DataFields = "open=openCol,close=closeCol,high=highCol,low=lowCol,xValue=timeCol"
Dim stockSC As SeriesCollection = de.GetFinancialSeries()
stockSC(0).Type = SeriesTypeFinancial.CandleStick
Chart.SeriesCollection.Add(stockSC)
For the next example, we'll get our data from a database that has only the price column where the entries represent a price snapshot for every hour of the day over several months. We'll want to create the same type of chart as the above but obviously the data is not formatted in this manner. Fortunately the DataEngine is capable of grouping the data properly and calculating the high, low, open, and close prices. The DataEngine will know that this is the result we're going for when we use GetDataFinancial() instead of GetData().
[C#]DataEngine de = new DataEngine(myConnectionString);
de.DateGrouping = TimeInterval.Days;
de.QueryString = "SELECT timeCol, price FROM stockPrice";
SeriesCollection stockSC = de.GetFinancialSeries();
stockSC.Type = SeriesTypeFinancial.CandleStick;
Chart.SeriesCollection.Add(stockSC);
[Visual Basic]Dim de As New DataEngine(myConnectionString)
de.DateGrouping = TimeInterval.Days
de.QueryString = "SELECT timeCol, price FROM stockPrice"
Dim stockSC As SeriesCollection = de.GetFinancialSeries()
stockSC.Type = SeriesTypeFinancial.CandleStick
Chart.SeriesCollection.Add(stockSC)
For more information on data acquisition, see: Data Tutorials.
Setting up Charts
ChartType.Financial
Please note that this chart type should not be used. It is there for backward compatibility. Using this chart type, a single series can be used where the element price properties are set as well as the volume value, however, the functionality will be limited. Instead use ChartType.Combo. The following example will show how to create the volume chart area using the newer more capable method.
[C#]DataEngine de = new DataEngine(myConnectionString);
de.QueryString = "SELECT timeCol, volume, FROM stockVolume";
de.DateGrouping = TimeInterval.Day;
SeriesCollection volSC = de.GetData();
// Create a new chart area, add the volume data and add the area to the chart.
ChartArea vca = new ChartArea(volSC);
vca.HeightPercentage = 30;
Chart.ExtraChartAreas.Add(vca);
[Visual Basic]Dim de As New DataEngine(myConnectionString)
de.QueryString = "SELECT timeCol, volume, FROM stockVolume"
de.DateGrouping = TimeInterval.Day
Dim volSC As SeriesCollection = de.GetData()
// Create a new chart area, add the volume data and add the area to the chart.
Dim vca As New ChartArea(volSC)
vca.HeightPercentage = 30
Chart.ExtraChartAreas.Add(vca)
For more information on using and manipulating ChartAreas, see: Multiple Chart Areas.